package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.service.wx.WxUserService;
import com.cskaoyan.market.util.ResponseUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName WxUserController
 * @Description
 * @Author MZ
 * @Date 2023/5/24 14:39
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {
    @Autowired
    WxUserService wxUserService;

    @GetMapping("index")
    public Object index() {

        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        Integer userId = (Integer) session.getAttribute("userId");
        if (userId == null) {
            return ResponseUtil.unlogin();
        }
        Map<String,Long> order = wxUserService.getUserIndex(userId);

        Map<String,Object> result = new HashMap<>();
        result.put("order",order);
        return ResponseUtil.ok(result);
    }

}
